# coding=UTF-8
from django.db.models import ProtectedError


class OrderType():
    '''
    数据排序类型
    '''
    # 正序
    ASC = 'asc'
    # 逆序
    DESC = 'desc'

class ViewStatus():

    '''
    视图返回状态码
    '''
    SUCCESS = 0
    FAILURE = 1

class ExceptionParse():
    '''
    异常解析
    '''
    DEFAULT_MSG = '失败'
    exception_dict = {
        AttributeError: '找不到数据',
        ProtectedError: '该数据为外键关联数据，需先处理外键数据，才能处理该数据',
    }

    @classmethod
    def parse(cls, e):
        e_class = type(e)
        msg = cls.exception_dict.get(e_class, '')
        if not msg:
            msg = cls.DEFAULT_MSG
        return msg